package com.daidai.controller;

import com.daidai.domain.Book;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/books")
public class BookContoller {

    @GetMapping
    public List<Book> getAllBooks(){
        List<Book> bookList = new ArrayList<>();

        Book book1 = new Book();
        book1.setId(1);
        book1.setType("入门");
        book1.setName("java从入门到精通");
        book1.setDescription("这是一本好书");

        Book book2 = new Book();
        book2.setId(2);
        book2.setType("入门");
        book2.setName("python从入门到精通");
        book2.setDescription("这也是一本好书");

        bookList.add(book1);
        bookList.add(book2);

        System.out.println(bookList);

        return bookList;
    }

    @PostMapping
    public String saveBook(@RequestBody Book book){
        System.out.println(book);
        return "save boo success..";
    }

}
